package net.crowdloud.server.DatabaseAccess.groups;

import javax.jdo.PersistenceManager;

import net.crowdloud.client.groups.GroupsDatabaseServerCalls;
import net.crowdloud.server.DatabaseAccess.DatabaseConnection;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * 
 * @Architecture
 */
@SuppressWarnings("serial")
public class GroupsDatabaseImplementation extends RemoteServiceServlet
		implements GroupsDatabaseServerCalls {

	@Override
	public String getGroups() {

		PersistenceManager persistenceManager = DatabaseConnection.connect();

		Groups groups = GetGroups.get(persistenceManager);

		persistenceManager.close();

		return groups.getGroupsList().getValue();
	}

	@Override
	public void addGroups(net.crowdloud.shared.entities.Groups groups) {

		PersistenceManager persistenceManager = DatabaseConnection.connect();

		SaveGroups.addNew(persistenceManager, groups);

		persistenceManager.close();
	}

	@Override
	public void updateGroups(net.crowdloud.shared.entities.Groups groups) {

		PersistenceManager persistenceManager = DatabaseConnection.connect();

		SaveGroups.update(persistenceManager, groups);

		persistenceManager.close();

	}
}
